var Emailer;

if (Emailer == undefined)
	Emailer = new function() {

		// Self reference.
		var Emailer = this;

		this.send = function send(event) {

			var mail = "mailto:" + form.to.value + "?cc=" + form.cc.value
					+ "&bcc=" + form.bcc.value + "&subject="
					+ form.subject.value + "&body="
					+ encodeURIComponent(form.body.value);

			chrome.tabs.create({
				url : mail,
			}, function callback() {
				window.close();
			});

		};

		this.load = function load(event) {

			chrome.tabs.query({
				currentWindow : true,
				active : true
			}, function callback(tabs) {
				var tab = tabs[0];
				form.subject.value = tab.title;
				form.body.value = tab.url;

				form.send.onclick = Emailer.send;
			});
		};
	};

window.addEventListener("load", Emailer.load);
